package com.lp.controller.iot;

import com.lp.bean.TVideoPlayUrl;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.util.ResultMapUtils;
import com.lp.util.iot.LiveNVSUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
public class TVideoPlayUrlController extends BaseController {

    @Resource
    public LiveNVSUtil liveNVSUtil;

    /**
     * 检索
     * @param response
     * @param tVideoPlayUrl
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = RequestURLIOT.VideoPlayUrl.VIDEO_PLAY_URL_PAGE)
    public ModelAndView selectPage(HttpServletResponse response,
                                          @RequestHeader(value = ResultMapUtils.USER_KEY, required = false) String userKey ,
                                          @RequestBody TVideoPlayUrl tVideoPlayUrl,
                                          @RequestParam(required=false) Integer pageSize ,
                                          @RequestParam Integer paged ) {
        Map<String, Object> resultMap = getResultMap();
        try {
            List<TVideoPlayUrl> info = (List<TVideoPlayUrl>)getData(service.selectPageList("TVideoPlayUrl.selectPageList",getPageBean(paged,pageSize), tVideoPlayUrl));
            for (TVideoPlayUrl videoPlayUrl : info) {
                videoPlayUrl.setUrl(videoPlayUrl.getUrl() + "?token=" + liveNVSUtil.getServerToken(videoPlayUrl.getIp()));
            }
            resultMap.put(ResultMapUtils.PLAT_REPONSE_DATA, info);
        } catch (Exception e) {
            exception(e,resultMap, tVideoPlayUrl);
        }
        return getModelAndView(response, resultMap);
    }
}
